package mware_lib.namensdienst.communication;

import java.io.*;
import java.net.Socket;

public class ObjectConnection {
	private ObjectInputStream objectIn;
    private ObjectOutputStream objectOut;
    private Socket sock;
	
	public ObjectConnection(Socket sock) throws IOException {
		InputStream in = sock.getInputStream();
		OutputStream out = sock.getOutputStream();
		
		this.objectOut = new ObjectOutputStream(out);
		this.objectIn = new ObjectInputStream(in);
		
		this.sock = sock;
	}

	public Object receive() throws IOException, ClassNotFoundException {
		return objectIn.readObject();
	}

	public void send(Object msg) throws IOException {
		objectOut.writeObject(msg);
	}

	public void close() throws IOException {
		objectIn.close();
		objectOut.close();
		sock.close();
	}
}
